package com.ys.nms.module.business.service.alertLog;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.ys.nms.module.business.controller.admin.alertLog.vo.*;
import com.ys.nms.module.business.dal.dataobject.alertLog.AlertLogDO;
import com.ys.nms.framework.common.pojo.PageResult;
import com.ys.nms.framework.common.pojo.PageParam;
import com.ys.nms.framework.common.util.object.BeanUtils;

import com.ys.nms.module.business.dal.mysql.alertLog.AlertLogMapper;

import static com.ys.nms.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.ys.nms.framework.common.util.collection.CollectionUtils.convertList;
import static com.ys.nms.framework.common.util.collection.CollectionUtils.diffList;
import static com.ys.nms.module.business.enums.ErrorCodeConstants.*;

/**
 * 报警日志 Service 实现类
 *
 * @author zzy
 */
@Service
@Validated
public class AlertLogServiceImpl implements AlertLogService {

    @Resource
    private AlertLogMapper alertLogMapper;

    @Override
    public Integer createAlertLog(AlertLogSaveReqVO createReqVO) {
        // 插入
        AlertLogDO alertLog = BeanUtils.toBean(createReqVO, AlertLogDO.class);
        alertLogMapper.insert(alertLog);

        // 返回
        return alertLog.getId();
    }

    @Override
    public void updateAlertLog(AlertLogSaveReqVO updateReqVO) {
        // 校验存在
        validateAlertLogExists(updateReqVO.getId());
        // 更新
        AlertLogDO updateObj = BeanUtils.toBean(updateReqVO, AlertLogDO.class);
        alertLogMapper.updateById(updateObj);
    }

    @Override
    public void deleteAlertLog(Integer id) {
        // 校验存在
        validateAlertLogExists(id);
        // 删除
        alertLogMapper.deleteById(id);
    }

    @Override
        public void deleteAlertLogListByIds(List<Integer> ids) {
        // 删除
        alertLogMapper.deleteByIds(ids);
        }


    private void validateAlertLogExists(Integer id) {
        if (alertLogMapper.selectById(id) == null) {
            throw exception(ALERT_LOG_NOT_EXISTS);
        }
    }

    @Override
    public AlertLogDO getAlertLog(Integer id) {
        return alertLogMapper.selectById(id);
    }

    @Override
    public PageResult<AlertLogDO> getAlertLogPage(AlertLogPageReqVO pageReqVO) {
        return alertLogMapper.selectPage(pageReqVO);
    }

}